//
//  BaseViewController.m
//  tesDemo02
//
//  Created by 拓客营 on 2022/3/21.
//

#import "BaseViewController.h"
#import "SDImageCache.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.view.backgroundColor = kRGB(0xF7F7F7);
//    self.view.backgroundColor = UIColor.whiteColor;
 
    [self adapterIOS11];
    
    [self adapterIOS15];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    // 必须放在 viewDidAppear: 方法里面才起效果（自动调用 preferredStatusBarStyle）
    // 放在 viewWillAppear: 方法里面不起效果
    [self setNeedsStatusBarAppearanceUpdate];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    //内存警告时清理一下图片缓存
    [[SDImageCache sharedImageCache] clearMemory];
}

- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
    DLog(@"%@:当前页面已销毁", NSStringFromClass([self class]));
}

- (UIStatusBarStyle)preferredStatusBarStyle {
//    if (self.bk_navigationBarStyle == BKNavigationStyleTheme) {
//        return UIStatusBarStyleLightContent;
//    }
    return UIStatusBarStyleDefault;
}

// 导航栏渐变
- (void)transitionWithScorllView:(UIScrollView *)scrollView
                 backgroundColor:(UIColor *)backgroundColor
                           title:(NSString *)title {
    
    CGFloat offsetY = scrollView.contentOffset.y;
    CGFloat alpha = offsetY / NavigationBarHeight;
//    [self ss_setNavigationTempAlpha:alpha];
//    self.ss_prefersnavigationBarColor = backgroundColor;
//
//    if (alpha <= 0) {
//        [self bk_resetNavigationBarStyle];
//    }
//
//    self.navigationItem.title = offsetY > kNavigationBarHeight ? title : @"";
}

- (void)adapterIOS11{
    // 适配iOS11以上UITableview 、UICollectionView、UIScrollview 列表/页面偏移
    if (@available(iOS 11.0, *)){
        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];

        [[UITableView appearance] setEstimatedRowHeight:0];
        [[UITableView appearance] setEstimatedSectionFooterHeight:0];
        [[UITableView appearance] setEstimatedSectionHeaderHeight:0];
    }
}

-(void)adapterIOS15 {
    if (@available(iOS 15.0, *)){
        [UITableView appearance].sectionHeaderTopPadding = 0;
    }
}



-(BaseEmptyDelegator *)emptyDelegator {
    if (!_emptyDelegator) {
        _emptyDelegator = [BaseEmptyDelegator new];
    }
    return _emptyDelegator;
}
@end
